package com.ybdz.scanner.api;

import com.ybdz.scanner.bean.ChuKuDanBean;
import com.ybdz.scanner.bean.InputBean;
import com.ybdz.scanner.bean.InputWeightBean;
import com.ybdz.scanner.bean.LoginBean;
import com.ybdz.scanner.bean.QueryBean;
import com.ybdz.scanner.bean.TakeCommitBean;
import com.ybdz.scanner.bean.TakeInventoryBean;
import com.ybdz.scanner.bean.UpdataBean;
import com.ybdz.scanner.utils.SPUtils;
import com.ybdz.scanner.utils.UIUtils;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;

/**
 * @ClassName: ApiStore
 * @author: zhao
 * @Description:    网络请求方法
 * @date 2018/2/24 12:02
 */
public class ApiStore {

    /**
     * 登录请求
     * @param mName
     * @param mPass
     * @param IEMI
     * @return
     */
    public static Call<LoginBean> login(String mName, String mPass, String IEMI){
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name", mName);
        hashMap.put("password", mPass);
        hashMap.put("deviceID", IEMI);
        Call<LoginBean> token = ApiFactory.get().getToken(hashMap);
        return token;
    }

    /**
     * 入库扫码请求
     * @param result
     * @return
     */
    public static Call<InputBean> getInput(String result){
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name", SPUtils.getString(UIUtils.getContext(),"usename","deUseName"));
        hashMap.put("deviceID", SPUtils.getString(UIUtils.getContext(),"IEMI","deIEMI"));
        hashMap.put("id",result);
        Call<InputBean> input = ApiFactory.get().getInput(hashMap);
        return input;
    }

    /**
     * 入库录入重量提交请求
     * @param scanResult
     * @param weight
     * @param isConformity
     * @return
     */
    public static Call<InputWeightBean> commitWeight(String scanResult, String weight, String isConformity){
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name", SPUtils.getString(UIUtils.getContext(), "usename", "deUseName"));
        hashMap.put("deviceID", SPUtils.getString(UIUtils.getContext(), "IEMI", "deIEMI"));
        hashMap.put("id", scanResult);
        hashMap.put("actualWeight",weight);
        hashMap.put("isQualified", isConformity);
        Call<InputWeightBean> inputWeight = ApiFactory.get().getInputWeight(hashMap);
        return inputWeight;
    }

    /**
     * 查询的扫描请求
     * @param result
     * @return
     */
    public static Call<QueryBean> getQuery(String result){
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name", SPUtils.getString(UIUtils.getContext(),"usename","deUseName"));
        hashMap.put("deviceID", SPUtils.getString(UIUtils.getContext(),"IEMI","deIEMI"));
        hashMap.put("id",result);
        Call<QueryBean> query = ApiFactory.get().getQuery(hashMap);
        return query;
    }

    /**
     * 出库单的网络请求
     * @param id
     * @return
     */
    public static Call<ChuKuDanBean> takeTable(String id){
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name", SPUtils.getString(UIUtils.getContext(),"usename","deUseName"));
        hashMap.put("deviceID", SPUtils.getString(UIUtils.getContext(),"IEMI","deIEMI"));
        hashMap.put("id",id);
        Call<ChuKuDanBean> takeTable = ApiFactory.get().takeTable(hashMap);
        return takeTable;
    }

    /**
     * 扫描出库单品的网络请求
     * @param result
     * @param outFormId
     * @return
     */
    public static Call<TakeInventoryBean> getTake(String result, String outFormId){
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name", SPUtils.getString(UIUtils.getContext(),"usename","deUseName"));
        hashMap.put("deviceID", SPUtils.getString(UIUtils.getContext(),"IEMI","deIEMI"));
        hashMap.put("id",result);
        hashMap.put("outFormId",outFormId);
        Call<TakeInventoryBean> outTake = ApiFactory.get().getOut(hashMap);
        return outTake;
    }

    /**
     * 出库单品提交
     * @param id
     * @param formId
     * @param productBatch
     * @return
     */
    public static Call<TakeCommitBean> saveOut(String id, String skuId, String formId,String productBatch){
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("name", SPUtils.getString(UIUtils.getContext(),"usename","deUseName"));
        hashMap.put("deviceID", SPUtils.getString(UIUtils.getContext(),"IEMI","deIEMI"));
        hashMap.put("id",id);
        hashMap.put("skuId",skuId);
        hashMap.put("formId",formId);
        hashMap.put("productBatch",productBatch);
        hashMap.put("creator",SPUtils.getString(UIUtils.getContext(),"IEMI","deIEMI"));
        Call<TakeCommitBean> takeInventoryBeanCall = ApiFactory.get().saveOut(hashMap);
        return takeInventoryBeanCall;
    }

    /*
        版本更新
    */

    public static Call<UpdataBean> update(){
        Call<UpdataBean> updateBeanCall = ApiFactory.get().update();
        return updateBeanCall;
    }
}
